<?php

namespace Publish\Models;

class ModelUser extends ModelBase
{
    public function getSource()
    {
        return 'users';
    }

    /**
     * 根据用户名获得用户信息
     * @param $username
     * @return bool
     */
    public static function getDataByUsername($username)
    {
        return static::getDataByFieldWithValue($username, 'username');
    }

    /**
     * 检查用户名密码是否正确
     * @param $username
     * @param $password
     * @return bool
     */
    public static function checkUsernameAndPassword($username, $password)
    {
        if ($username == null || !is_string($username) || trim($username) == '') {
            return false;
        }
        $param = array(
            'conditions' => " username = :username: AND password = :password: ",
            'bind'       => array(
                'username' => $username,
                'password' => md5($password),
            ),
        );
        $count = static::count($param);
        if ($count > 0) {
            return true;
        } else {
            return false;
        }
    }
}
